#!/bin/bash

. CONFIG

# take $1 as install dir, if provided.

[[ -z $1 ]] || INSTALL_DIR=$1
echo $@|grep onlycopy && ONLYCOPY=true

if [[ -z $INSTALL_DIR ]];then
	echo undefined target install directory
	exit -1
else 
	echo installing slider to $INSTALL_DIR
fi

mkdir -p $INSTALL_DIR/bin \
         $INSTALL_DIR/etc \
         $INSTALL_DIR/share/xlider/fonts \
         $INSTALL_DIR/share/xlider/images \
         $INSTALL_DIR/share/xlider/themes \
         $INSTALL_DIR/share/xlider/script \
         $INSTALL_DIR/share/man/man1 \
         $INSTALL_DIR/share/doc/xlider

cp src/xlider $INSTALL_DIR/bin
cp fonts/* $INSTALL_DIR/share/xlider/fonts
cp images/* $INSTALL_DIR/share/xlider/images
cp themes/* $INSTALL_DIR/share/xlider/themes
cp script/* $INSTALL_DIR/share/xlider/script
cp doc/* $INSTALL_DIR/share/doc/xlider
gzip -f --best $INSTALL_DIR/share/doc/xlider/changelog*

[[ -z $ONLYCOPY ]] || exit 0

# make a configuration file
echo -e "<xlider home=\"$INSTALL_DIR/share/xlider\" />" > $INSTALL_DIR/etc/xliderconf

# make link

#if [[ -d $HOME/bin ]]; then
#	[[ -f $HOME/bin/xlider ]] && rm $HOME/bin/xlider
#	ln -s $INSTALL_DIR/bin/xlider $HOME/bin/xlider
#fi

[[ -f $HOME/.xliderconf ]]||cp $INSTALL_DIR/etc/xliderconf $HOME/.xliderconf
